Rebase `cargo rustdoc` and tweak behavior
authorAlex Crichton <alex@alexcrichton.com>
Mon, 9 Nov 2015 16:36:52 +0000 (08:36 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 9 Nov 2015 16:36:52 +0000 (08:36 -0800)
This rebases #1977 onto master and also tweaks the behavior to match `cargo
rustc` when there are multiple targets in play.

12 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/doc.rs
src/bin/install.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/rustdoc.rs
src/bin/test.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_rustdoc.rs

index 47f5b9a939b410e79a0ea34a505df872cdffd286..224f5ab3cc4433d16e8d496b5e0c5cbd654ae229 100644 (file)
@@ -84,7 +84,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                             &options.flag_test,
                                             &options.flag_example,
                                             &options.flag_bench),
-            extra_rustdoc_args: Vec::new(),
+            target_rustdoc_args: None,
             target_rustc_args: None,
         },
     };
index 92971e77db5d6904c485f9097a3252c0d5d8d9f4..5db738b18f0239c1d0ab024bb5425cb739e39cdb 100644 (file)
@@ -81,7 +81,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                         &options.flag_test,
                                         &options.flag_example,
                                         &options.flag_bench),
-        extra_rustdoc_args: Vec::new(),
+        target_rustdoc_args: None,
         target_rustc_args: None,
     };
 
index 0ac61d6bd8255705876978f65657b4eb51729bca..df110f93bc1cd21350b22194eb8fdcfbbb142e51 100644 (file)
@@ -70,7 +70,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                 deps: !options.flag_no_deps,
             },
             target_rustc_args: None,
-            extra_rustdoc_args: Vec::new(),
+            target_rustdoc_args: None,
         },
     };
 
index db96c81b41f39b1d37432e4f891e0cda3affd89b..141956179f26f0e596a9794b46606f18138c7c74 100644 (file)
@@ -95,6 +95,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         filter: ops::CompileFilter::new(false, &options.flag_bin, &[],
                                         &options.flag_example, &[]),
         target_rustc_args: None,
+        target_rustdoc_args: None,
     };
 
     let source = if let Some(url) = options.flag_git {
index d74b5d45720eb5b063b18b4ad80618891f3f322d..797b120a589a2a3b3abb97c96f4ab1c72a971374 100644 (file)
@@ -80,7 +80,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                 bins: &bins, examples: &examples,
             }
         },
-        extra_rustdoc_args: Vec::new(),
+        target_rustdoc_args: None,
         target_rustc_args: None,
     };
 
index 78a17dadaa53411bfdc21bc30667abc2c27aca1d..c4ae23268353231dc6dd6eeb84b5a9f7831b726e 100644 (file)
@@ -84,7 +84,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                         &options.flag_test,
                                         &options.flag_example,
                                         &options.flag_bench),
-        extra_rustdoc_args: Vec::new(),
+        target_rustdoc_args: None,
         target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
     };
 
index 181cbf8a9aa70115f03dddccfbdaddddecf7123c..e62adc87fc56eacd5ae03dc41f52f09697257896 100644 (file)
@@ -1,5 +1,5 @@
 use cargo::ops;
-use cargo::util::{CliResult, CliError, Config};
+use cargo::util::{CliResult, Config};
 use cargo::util::important_paths::{find_root_manifest_for_cwd};
 
 #[derive(RustcDecodable)]
@@ -10,13 +10,17 @@ struct Options {
     flag_jobs: Option<u32>,
     flag_manifest_path: Option<String>,
     flag_no_default_features: bool,
-    flag_no_deps: bool,
     flag_open: bool,
     flag_verbose: bool,
     flag_release: bool,
     flag_quiet: bool,
     flag_color: Option<String>,
     flag_package: Option<String>,
+    flag_lib: bool,
+    flag_bin: Vec<String>,
+    flag_example: Vec<String>,
+    flag_test: Vec<String>,
+    flag_bench: Vec<String>,
 }
 
 pub const USAGE: &'static str = "
@@ -29,8 +33,12 @@ Options:
     -h, --help               Print this message
     --open                   Opens the docs in a browser after the operation
     -p SPEC, --package SPEC  Package to document
-    --no-deps                Don't build documentation for dependencies
     -j N, --jobs N           The number of jobs to run in parallel
+    --lib                    Build only this package's library
+    --bin NAME               Build only the specified binary
+    --example NAME           Build only the specified example
+    --test NAME              Build only the specified test target
+    --bench NAME             Build only the specified benchmark target
     --release                Build artifacts in release mode, with optimizations
     --features FEATURES      Space-separated list of features to also build
     --no-default-features    Do not build the `default` feature
@@ -40,15 +48,12 @@ Options:
     -q, --quiet              No output printed to stdout
     --color WHEN             Coloring: auto, always, never
 
-By default the documentation for the local package and all dependencies is
-built. The output is all placed in `target/doc` in rustdoc's usual format.
-
 The specified target for the current package (or package specified by SPEC if
-provided) will be documented along with all of its dependencies. The specified
-<opts>... will all be passed to the final rustdoc invocation, not any of the
-dependencies. Note that rustdoc will still unconditionally receive
-arguments such as -L, --extern, and --crate-type, and the specified <opts>...
-will simply be added to the rustdoc invocation.
+provided) will be documented with the specified <opts>... being passed to the
+final rustdoc invocation. Dependencies will not be documented as part of this
+command.  Note that rustdoc will still unconditionally receive arguments such
+as -L, --extern, and --crate-type, and the specified <opts>...  will simply be
+added to the rustdoc invocation.
 
 If the --package argument is given, then SPEC is a package id specification
 which indicates which package should be documented. If it is not given, then the
@@ -70,19 +75,21 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
             target: options.flag_target.as_ref().map(|t| &t[..]),
             features: &options.flag_features,
             no_default_features: options.flag_no_default_features,
-            spec: options.flag_package.as_ref().map(|s| &s[..]),
+            spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]),
             exec_engine: None,
-            filter: ops::CompileFilter::Everything,
             release: options.flag_release,
-            mode: ops::CompileMode::Doc {
-                deps: !options.flag_no_deps,
-            },
-            extra_rustdoc_args: options.arg_opts,
+            filter: ops::CompileFilter::new(options.flag_lib,
+                                            &options.flag_bin,
+                                            &options.flag_test,
+                                            &options.flag_example,
+                                            &options.flag_bench),
+            mode: ops::CompileMode::Doc { deps: false },
+            target_rustdoc_args: Some(&options.arg_opts),
             target_rustc_args: None,
         },
     };
 
-    try!(ops::doc(&root, &mut doc_opts).map_err(|err| CliError::from_boxed(err, 101)));
+    try!(ops::doc(&root, &mut doc_opts));
 
     Ok(None)
 }
index 16c3e1fb3f7997d70aebdf747c91b4006333c136..5afb9b8e8bd54107a456f8675843cfe547b8c31c 100644 (file)
@@ -90,7 +90,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                             &options.flag_test,
                                             &options.flag_example,
                                             &options.flag_bench),
-            extra_rustdoc_args: Vec::new(),
+            target_rustdoc_args: None,
             target_rustc_args: None,
         },
     };
index 0484d8023fec116476d646bc07d0536460ed6482..073d5929335e8e3fd0ffd20dadc3859481c966f4 100644 (file)
@@ -58,7 +58,7 @@ pub struct CompileOptions<'a> {
     /// Mode for this compile.
     pub mode: CompileMode,
     /// Extra arguments to be passed to rustdoc (for main crate and dependencies)
-    pub extra_rustdoc_args: Vec<String>,
+    pub target_rustdoc_args: Option<&'a [String]>,
     /// The specified target will be compiled with all the available arguments,
     /// note that this only accounts for the *final* invocation of rustc
     pub target_rustc_args: Option<&'a [String]>,
@@ -147,7 +147,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
     let CompileOptions { config, jobs, target, spec, features,
                          no_default_features, release, mode,
                          ref filter, ref exec_engine,
-                         ref extra_rustdoc_args,
+                         ref target_rustdoc_args,
                          ref target_rustc_args } = *options;
 
     let target = target.map(|s| s.to_string());
@@ -188,29 +188,44 @@ pub fn compile_pkg<'a>(root_package: &Package,
     let mut package_targets = Vec::new();
 
     let profiles = root_package.manifest().profiles();
-    match *target_rustc_args {
-        Some(args) => {
-            if to_builds.len() == 1 {
-                let targets = try!(generate_targets(to_builds[0], profiles,
-                                                    mode, filter, release));
-                if targets.len() == 1 {
-                    let (target, profile) = targets[0];
-                    let mut profile = profile.clone();
-                    profile.rustc_args = Some(args.to_vec());
-                    general_targets.push((target, profile));
-                } else {
-                    return Err(human("extra arguments to `rustc` can only be \
-                                      passed to one target, consider \
-                                      filtering\nthe package by passing e.g. \
-                                      `--lib` or `--bin NAME` to specify \
-                                      a single target"))
-
-                }
+    match (*target_rustc_args, *target_rustdoc_args) {
+        (Some(..), _) |
+        (_, Some(..)) if to_builds.len() != 1 => {
+            panic!("`rustc` and `rustdoc` should not accept multiple `-p` flags")
+        }
+        (Some(args), _) => {
+            let targets = try!(generate_targets(to_builds[0], profiles,
+                                                mode, filter, release));
+            if targets.len() == 1 {
+                let (target, profile) = targets[0];
+                let mut profile = profile.clone();
+                profile.rustc_args = Some(args.to_vec());
+                general_targets.push((target, profile));
+            } else {
+                return Err(human("extra arguments to `rustc` can only be \
+                                  passed to one target, consider \
+                                  filtering\nthe package by passing e.g. \
+                                  `--lib` or `--bin NAME` to specify \
+                                  a single target"))
+            }
+        }
+        (None, Some(args)) => {
+            let targets = try!(generate_targets(to_builds[0], profiles,
+                                                mode, filter, release));
+            if targets.len() == 1 {
+                let (target, profile) = targets[0];
+                let mut profile = profile.clone();
+                profile.rustdoc_args = Some(args.to_vec());
+                general_targets.push((target, profile));
             } else {
-                panic!("`rustc` should not accept multiple `-p` flags")
+                return Err(human("extra arguments to `rustdoc` can only be \
+                                  passed to one target, consider \
+                                  filtering\nthe package by passing e.g. \
+                                  `--lib` or `--bin NAME` to specify \
+                                  a single target"))
             }
         }
-        None => {
+        (None, None) => {
             for &to_build in to_builds.iter() {
                 let targets = try!(generate_targets(to_build, profiles, mode,
                                                     filter, release));
@@ -226,24 +241,6 @@ pub fn compile_pkg<'a>(root_package: &Package,
     }
 
     let mut ret = {
-    let mut target_with_rustdoc = None;
-    if !extra_rustdoc_args.is_empty() {
-        let mut target_with_rustdoc_inner = Vec::new();
-        for &(target, profile) in &targets {
-            if profile.doc {
-                let mut profile = profile.clone();
-                profile.rustdoc_args = Some(extra_rustdoc_args.clone());
-                target_with_rustdoc_inner.push((target, profile));
-            }
-        }
-        target_with_rustdoc = Some(target_with_rustdoc_inner);
-    };
-
-    let targets = target_with_rustdoc.as_ref().map_or(targets,
-                                             |o| o.into_iter()
-                                                  .map(|&(t, ref p)| (t, p))
-                                                  .collect());
-    let ret = {
         let _p = profile::start("compiling");
         let mut build_config = try!(scrape_build_config(config, jobs, target));
         build_config.exec_engine = exec_engine.clone();
index 45b966b59aa874363a412712fcd951c4886b00c4..76eab5396b43585ab393c1902144aa416f1efc7a 100644 (file)
@@ -220,7 +220,7 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path)
         exec_engine: None,
         release: false,
         mode: ops::CompileMode::Build,
-        extra_rustdoc_args: Vec::new(),
+        target_rustdoc_args: None,
         target_rustc_args: None,
     }));
 
index 2b738bc94358c51613b414425cfdb16c318fddd6..d62f8cbf1f717e676c416797106815f814628896 100644 (file)
@@ -395,7 +395,7 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
         }
     }
 
-    if let Some(ref args) = profile.rustdoc_args {
+    if let Some(ref args) = unit.profile.rustdoc_args {
         rustdoc.args(args);
     }
 
index 775051ffca5785025ef3d25399f80196a7ef8510..83084fc4ff274d0e15214cedcba861f689fc1874 100644 (file)
@@ -1,6 +1,6 @@
 use std::path::MAIN_SEPARATOR as SEP;
 use support::{execs, project};
-use support::{COMPILING, RUNNING};
+use support::{COMPILING, RUNNING, DOCUMENTING};
 use hamcrest::{assert_that};
 
 fn setup() {
@@ -21,13 +21,13 @@ test!(rustdoc_simple {
                 execs()
                 .with_status(0)
                 .with_stdout(format!("\
-{compiling} foo v0.0.1 ({url})
+{documenting} foo v0.0.1 ({url})
 {running} `rustdoc src{sep}lib.rs --crate-name foo \
         -o {dir}{sep}target{sep}doc \
         -L dependency={dir}{sep}target{sep}debug \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
 ",
-            running = RUNNING, compiling = COMPILING, sep = SEP,
+            running = RUNNING, documenting = DOCUMENTING, sep = SEP,
             dir = p.root().display(), url = p.url())));
 });
 
@@ -45,14 +45,14 @@ test!(rustdoc_args {
                 execs()
                 .with_status(0)
                 .with_stdout(format!("\
-{compiling} foo v0.0.1 ({url})
+{documenting} foo v0.0.1 ({url})
 {running} `rustdoc src{sep}lib.rs --crate-name foo \
         -o {dir}{sep}target{sep}doc \
         --no-defaults \
         -L dependency={dir}{sep}target{sep}debug \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
 ",
-            running = RUNNING, compiling = COMPILING, sep = SEP,
+            running = RUNNING, documenting = DOCUMENTING, sep = SEP,
             dir = p.root().display(), url = p.url())));
 });
 
@@ -91,11 +91,7 @@ test!(rustdoc_foo_with_bar_dependency {
                 .with_stdout(format!("\
 {compiling} bar v0.0.1 ({url})
 {running} `rustc {bar_dir}{sep}src{sep}lib.rs [..]`
-{running} `rustdoc {bar_dir}{sep}src{sep}lib.rs --crate-name bar \
-        -o {dir}{sep}target{sep}doc \
-        -L dependency={dir}{sep}target{sep}debug{sep}deps \
-        -L dependency={dir}{sep}target{sep}debug{sep}deps`
-{compiling} foo v0.0.1 ({url})
+{documenting} foo v0.0.1 ({url})
 {running} `rustdoc src{sep}lib.rs --crate-name foo \
         -o {dir}{sep}target{sep}doc \
         --no-defaults \
@@ -104,6 +100,7 @@ test!(rustdoc_foo_with_bar_dependency {
         --extern [..]`
 ",
             running = RUNNING, compiling = COMPILING, sep = SEP,
+            documenting = DOCUMENTING,
             dir = foo.root().display(), url = foo.url(),
             bar_dir = bar.root().display())));
 });
@@ -142,14 +139,14 @@ test!(rustdoc_only_bar_dependency {
                 execs()
                 .with_status(0)
                 .with_stdout(format!("\
-{compiling} bar v0.0.1 ({url})
+{documenting} bar v0.0.1 ({url})
 {running} `rustdoc {bar_dir}{sep}src{sep}lib.rs --crate-name bar \
         -o {dir}{sep}target{sep}doc \
         --no-defaults \
         -L dependency={dir}{sep}target{sep}debug{sep}deps \
         -L dependency={dir}{sep}target{sep}debug{sep}deps`
 ",
-            running = RUNNING, compiling = COMPILING, sep = SEP,
+            running = RUNNING, documenting = DOCUMENTING, sep = SEP,
             dir = foo.root().display(), url = foo.url(),
             bar_dir = bar.root().display())));
 });